//
//  HomeProdViewFrame.m
//  JiaoX
//
//  Created by 尹桥印 on 14/11/13.
//  Copyright (c) 2014年 北京娇羞科技有限公司. All rights reserved.
//

#import "HomeProdViewFrame.h"
#import "ProductItemInfo.h"
#import "ProdPromotion.h"

@implementation HomeProdViewFrame

-(void)setProduct:(ProductItemInfo *)product{
    _product = product;
    
    // 1.商品头图
    CGFloat prodImaegX = JXPublicInset;
    CGFloat prodImaegY = JXPublicInset;
    CGFloat prodImaegW = PROD_IMAGE_WIDTH;
    CGFloat prodImaegH = PROD_IMAGE_WIDTH;
    self.prodImageFrame = CGRectMake(prodImaegX, prodImaegY, prodImaegW, prodImaegH);
    
    // 2.商品标题
    CGFloat titleLabelX = CGRectGetMaxX(self.prodImageFrame) + JXPublicInset;
    CGFloat titleLabelY = JXPublicInset;
    
    CGFloat maxW = JXScreenW-JXPublicInset-titleLabelX;
    CGSize maxTitleSize = CGSizeMake(maxW, MAXFLOAT);
    CGSize titleSize = [product.prodWholeName sizeWithFont:[UIFont systemFontOfSize:JXProdTitleSize] constrainedToSize:maxTitleSize];
    self.titleFrame =(CGRect){{titleLabelX, titleLabelY}, titleSize};
    
    // 3.商品原价
    CGFloat oldPriceX = titleLabelX;
    CGSize oldPriceSize = [product.prodOldPrice sizeWithFont:[UIFont systemFontOfSize:JXProdDisCountSize]];
    CGFloat oldPriceY = CGRectGetMaxY(self.prodImageFrame)-oldPriceSize.height;
    self.oldPriceLabelFrame = (CGRect){{oldPriceX, oldPriceY}, oldPriceSize};
    
    // 4.商品现价
    CGFloat nowPriceX = titleLabelX;
    CGSize nowPriceSize = [product.prodNewPrice sizeWithFont:[UIFont systemFontOfSize:JXProdNowPriceSize]];
    CGFloat nowPriceY = CGRectGetMaxY(self.titleFrame)+(CGRectGetMinY(self.oldPriceLabelFrame)-nowPriceSize.height-CGRectGetMaxY(self.titleFrame))*0.5;
    self.nowPriceLabelFrame =(CGRect){{nowPriceX, nowPriceY}, nowPriceSize};
    
    // 5.折扣
    CGFloat disCountX = CGRectGetMaxX(self.oldPriceLabelFrame)+JXPublicInset;
    CGFloat disCountY = oldPriceY;
    CGSize disCountSize = [product.prodDiscount sizeWithFont:[UIFont systemFontOfSize:JXProdDisCountSize]];
    self.disCountLabelFrame = (CGRect){{disCountX,disCountY},disCountSize};
    
    // 6.讨论人数或者购买人数
    CGFloat buyCountX =CGRectGetMaxX(self.disCountLabelFrame)+JXPublicInset;
    CGFloat buyCountY = self.nowPriceLabelFrame.origin.y;
    CGFloat buyCountW = JXScreenW-buyCountX-JXPublicInset;
    CGSize buyCountSize = [[NSString stringWithFormat:@"%@",product.prodBuyCount] sizeWithFont:[UIFont systemFontOfSize:14]];
    self.comtCountLabelFrame = CGRectMake(buyCountX, buyCountY, buyCountW, buyCountSize.height);
    
    // 7.计算赠品button
    CGFloat giftX = oldPriceX;
    CGFloat giftY = oldPriceY;
    CGSize giftSize = CGSizeMake(0, 0);
    if(product.prodPromotion.presentList.count){
        giftSize = CGSizeMake(JXScreenW-CGRectGetMaxX(self.prodImageFrame)-JXPublicInset*2, 17);
    }
    self.giftFrame = (CGRect){{giftX, giftY},giftSize};
    
    
    self.cellHeight = CGRectGetMaxY(self.prodImageFrame)+JXPublicInset;
    
    // 自己的frame
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat w = JXScreenW;
    CGFloat h = self.cellHeight;
    self.frame = CGRectMake(x, y, w, h);
    
}
@end
